/*
 * @lc app=leetcode.cn id=169 lang=javascript
 *
 * [169] 多数元素
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {number}
 */
var majorityElement = function(nums) {
  let count = 0;
  let temp = null;
  for(const num of nums) {
    if (count === 0) {
      temp = num;
      count++;
    } else if (temp === num) {
      count++;
    } else {
      count--;
    }
  }
  return temp;
};
// @lc code=end

